package org.vy.dal.dao.lookup;

/**
 * @author Ravi Shankar
 *
 */

import java.util.List;

import org.vy.dal.QueryManager;

public class VyLookupReligionDAO {

	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE religion_code = m_ReligionCode";
	private static final String FIND_BY_PARAM = "SELECT * FROM <TABLE> WHERE 1 = 1 ";
	private static final String UPDATE = "UPDATE <TABLE> SET religion_code = m_ReligionCode,religion_name=m_ReligionName, is_active=m_IsActive, last_updated_by=m_LastUpdatedBy, last_updt_on=m_LastUpdtOn WHERE religion_code = m_ReligionCode";
	private static final String INSERT = "INSERT INTO <TABLE> (religion_code,religion_name,is_active,last_updated_by,last_updt_on) VALUES (m_ReligionCode,m_ReligionName,m_IsActive,m_LastUpdatedBy,m_LastUpdtOn)";

	public static VyLookupReligionDO findByPK(String key) throws Exception {
		VyLookupReligionDO dto = new VyLookupReligionDO();
		dto.setReligionCode(key);
		dto = (VyLookupReligionDO) QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}

	@SuppressWarnings("unchecked")
	public static List<VyLookupReligionDO> findByParam(VyLookupReligionDO dto)
			throws Exception {
		StringBuilder sb = new StringBuilder(FIND_BY_PARAM);
		if (dto.getReligionCode() != null) {
			sb.append(" AND religion_code LIKE '%" + dto.getReligionCode()
					+ "%' ");
		}
		if (dto.getReligionName() != null) {
			sb.append(" AND religion_name LIKE '%" + dto.getReligionName()
					+ "%' ");
		}
		if (dto.getIsActive() != null) {
			sb.append(" AND is_active LIKE '%" + dto.getIsActive()
					+ "%' ");
		}
		if (dto.getLastUpdatedBy() != null) {
			sb.append(" AND last_updated_by LIKE '%" + dto.getLastUpdatedBy()
					+ "%' ");
		}
		if (dto.getLastUpdtOn() != null) {
			sb.append(" AND last_updt_on LIKE '%" + dto.getLastUpdtOn()
					+ "%' ");
		}
		
		System.out.println(sb.toString());
		return (List<VyLookupReligionDO>) QueryManager.executeListQuery(dto, sb
				.toString());
	}

	public static VyLookupReligionDO insert(VyLookupReligionDO dto)
			throws Exception {

		dto = (VyLookupReligionDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyLookupReligionDO update(VyLookupReligionDO dto)
			throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}
}
